package com.smbms.commons.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smbms.commons.bean.Users;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UsersMapper extends BaseMapper<Users> {

    @Select("select id,userCode,userName,gender,birthday,phone,address,userRole,createdBy,creationDate,modifyBy,modifyDate,userstate,floor(DATEDIFF(NOW(),u.birthday)/365) as 'userAge' from smbms_user u where userstate=1 and userCode=#{userCode} and userPassword=md5(#{userPassword})")
    Users login(Users user);

    @Select("select u.id,userCode,userName,gender,if(gender=1,'女','男') as 'userSex',birthday,phone,address,userRole,u.createdBy,u.creationDate,u.modifyBy,u.modifyDate,userstate,floor(datediff(now(),u.birthday)/365) as 'userAge',r.id as 'roleId',r.roleName from smbms_user u left join smbms_role r on u.userRole=r.id where userstate=1")
    List<Users> findAllUsers();

    List<Users> findUserByNameAndRoleName(@Param("name")String name, @Param("roleId") Integer roleId);

}
